#include <std.h>
#include <system.h>
#include <pio.h>
#include <error.h>
#include <pipe.h>
#include <gserv.h>

void gsetcursor(int x,int y)
{
	bioscall(0x0200,0,0,y*0x100+x,0,0,0x10);
}

void ggetcursor(struct greq *gx)
{
	bioscall(0x0300,0,0,0,0,0,0x10);
	gx->x=cx;
	gx->y=dx;
}

void writech(int ch)
{
	struct greq g;
	getcursor(&g);
	setcursor(g.x+1,g.y);
	bioscall(0x0900+ch,15,1,0,0,0,0x10);
}

void putpixel(int x,int y,int color)
{
	bioscall(0x0c00+color,0,x,y,0,0,0x10);
}

int getpixel(int x,int y)
{
	bioscall(0x0d00,0,x,y,0,0,0x10);
	return (unsigned char)ax;
}

void box(int x,int y,int fx,int fy,int color)
{
	int r=x,s=y;
	while(++x<=fx)
		putpixel(x,y,color);
	while(++y<=fy)
		putpixel(x,y,color);
	while(--x>=r)
		putpixel(x,y,color);
	while(--y>=s)
		putpixel(x,y,color);
}


void execute_g(struct greq *gr)
{
	switch(gr->fn)	{
		case SETMODE: bioscall(gr->x,0,0,0,0,0,0x10);
		break;
		case SETCUR: gsetcursor(gr->x,gr->y);
		break;
		case SETPAL: setpalette(gr->color,gr->x,gr->y,gr->x1);
		break;
		case GETCUR: ggetcursor(gr);
		break;
		case WRITECH: writech(gr->x);
		break;
		case PUTPIXEL: putpixel(gr->x,gr->y,gr->color);
		break;
		case GETPIXEL: gr->color=getpixel(gr->x,gr->y);
		break;
		case BOX: box(gr->x,gr->y,gr->x1,gr->y1,gr->color);
		break;
	}
}

void init_gserver()
{

}
